package com.ewei.web.common.exception;

public class ExceptionUtils {
	private static final String MSG_PREFIX = "EXCPTION:";
	private static final String MSG_SEPERATOR = "| ";
	private static final String MSG_CLASS = " -Class:";
	private static final String MSG_METHOD = " -Method:";
	private static final String MSG_LINE=" -Line:";
	public static String traceMsg(Throwable throwable){
		if(null != throwable){
			StringBuilder builder = new StringBuilder();
			builder.append(MSG_PREFIX);
			Throwable t = throwable;
			do{
				builder.append(t.getLocalizedMessage());
				StackTraceElement element = t.getStackTrace()[0];
				builder.append(MSG_CLASS);
				builder.append(element.getClassName());
				builder.append(MSG_METHOD);
				builder.append(element.getMethodName());
				builder.append(MSG_LINE);
				builder.append(element.getLineNumber());
				t = t.getCause();
				if(null != t){
					builder.append(MSG_SEPERATOR);
				}
			}while(null != t);
			return builder.toString();
		}
		return null;
	}
}
